package com.controller;

import com.entity.CompanyInfo;
import com.repository.CompanyInfoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公司管理
 */

@RestController
@RequestMapping("/api/company")
public class CompanyController {

    @Autowired
    private CompanyInfoRepository companyInfoRepository;

    @PostMapping
    public void save(@RequestBody CompanyInfo company) {
        companyInfoRepository.save(company);

    }

    @GetMapping
    public List<CompanyInfo> list() {
        return companyInfoRepository.findAll();
    }

    @GetMapping("/{id}")
    public CompanyInfo get(@PathVariable Integer id) {
        return companyInfoRepository.findById(id).orElse(null);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id) {
        companyInfoRepository.deleteById(id);
    }
}